package com.caocaog.market.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caocaog.market.entity.ShopKilometerPrice;
import com.caocaog.market.mapper.ShopKilometerPriceMapper;
import com.caocaog.market.service.ShopKilometerPriceService;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * 公里价格
 *
 * @author chechen
 * @date 2021-11-30
 */
@Service
@Transactional
public class ShopKilometerPriceServiceImpl extends ServiceImpl<ShopKilometerPriceMapper, ShopKilometerPrice> implements ShopKilometerPriceService {

    @Override
    public ShopKilometerPrice queryShopKilometerPriceById(Serializable id) {
        return super.baseMapper.selectById(id);
    }

    @Override
    public Long addShopKilometerPrice(ShopKilometerPrice shopKilometerPrice) {
        super.baseMapper.insert(shopKilometerPrice);
        if (shopKilometerPrice.getId() == null)
            throw new JeecgBootException("新增公里价格失败");
        return shopKilometerPrice.getId();
    }

    @Override
    public List<ShopKilometerPrice> addBatchShopKilometerPrice(List<ShopKilometerPrice> shopKilometerPrices) {
        shopKilometerPrices.forEach(item -> {
            item.setId(null);
            super.baseMapper.insert(item);
        });
        return shopKilometerPrices;
    }

    @Override
    public int updateShopKilometerPrice(ShopKilometerPrice shopKilometerPrice) {
        int updateRecordCount = super.baseMapper.updateById(shopKilometerPrice);
        if (updateRecordCount == 0)
            throw new JeecgBootException("更新公里价格失败, id-> " + shopKilometerPrice.getId());
        return updateRecordCount;
    }

    @Override
    public int deleteBatchShopKilometerPrice(List<String> ids) {
        int deleteRecordCount = super.baseMapper.deleteBatchIds(ids);
        if (deleteRecordCount < ids.size())
            throw new JeecgBootException(
                    String.format("批量删除公里价格失败, deleteRecordCount-> %s, ids.size()-> %s, ids-> %s",
                            deleteRecordCount, ids.size(), ids));
        return deleteRecordCount;
    }

}
